package edu.scu.declaresys.web.util;

import edu.scu.declaresys.service.ServiceFactory;
import edu.scu.declaresys.util.Text;
import edu.scu.declaresys.vo.Project;

/**
 * 
 * @author: zt
 * @since : 2013-7-14
 */
public class ProjectUtils
{
	/**
	 * 
	 *@param project
	 *@return true all filled, otherwise false.
	 */
	public static boolean checkRequiredField(Project project)
	{
		return !(project.getProjectClassId() == null 
				|| Text.isNullOrEmpty(project.getName())
				|| Text.isNullOrEmpty(project.getProjectFileno())
				|| Text.isNullOrEmpty(project.getLegalMan())
				|| Text.isNullOrEmpty(project.getTechLeader())
				|| project.getFundType() == null
				|| project.getGrantFunds() == null
				|| project.getOtherFunds() == null
				|| project.getSelfRaisedFunds() == null
				|| Text.isNullOrEmpty(project.getIntro())
				);
	}
	
	public static void doLogicalValidation(Project project) throws Exception
	{
		// Check project class.
		if(ServiceFactory.createProjectClassService().findClass(project.getProjectClassId()) == null)
		{
			throw new Exception("项目类别不存在");
		}
		// Check project name.
		if(ServiceFactory.createProjectService().findByNameUnique(project.getName()) != null)
		{
			throw new Exception("项目名重复");
		}
		// fund type.
		if(!project.getFundType().equals(Project.FUND_THREE_CITY) 
				&& !project.getFundType().equals(Project.FUND_UNDEVOLOPED_AREA))
		{
			throw new Exception("项目资金类别不存在");
		}
		// check funds.
		if(project.getGrantFunds() < 0
				|| project.getOtherFunds() < 0
				|| project.getSelfRaisedFunds() < 0)
		{
			throw new Exception("资金不能为负");
		}
		return ;
	}

	
}
